//
//  YSGMyopiaRecordEyePressureCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/1/6.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class YSGMyopiaRecordEyePressureCell: UITableViewCell, UITextFieldDelegate {
    
    weak var delegate: YSGMyopiaRecordCellDelegate?
    
    private var currentIndexPath = IndexPath(row: 0, section: 0)
    private var checkInfo = YSGMyopiaRecordDetailCheckInfo()

    func configure(with checkInfo: YSGMyopiaRecordDetailCheckInfo, isEdited: Bool) {
        self.checkInfo = checkInfo
        titleLabel.text = checkInfo.title
        leftEyeTextField.text = checkInfo.osEyePressure
        rightEyeTextField.text = checkInfo.odEyePressure
        deleteBtn.isHidden = !checkInfo.isCanDelete
        
        leftEyeTextField.isEnabled = !isEdited
        rightEyeTextField.isEnabled = !isEdited
    }
    
    @IBAction private func deleteAction() {
        delegate?.eyePressureCell(deleteHandle: self)
    }
    
    @IBOutlet private weak var deleteBtn: UIButton!
    
    @IBOutlet private weak var titleLabel: UILabel!
    
    @IBOutlet private weak var leftEyeView: UIView! {
        didSet {
            leftEyeView.layer.cornerRadius = 16
            leftEyeView.setShadow()
        }
    }
    @IBOutlet private weak var rightEyeView: UIView! {
        didSet {
            rightEyeView.layer.cornerRadius = 16
            rightEyeView.setShadow()
        }
    }
    
    @IBOutlet private weak var leftEyeTextField: UITextField! {
        didSet {
            leftEyeTextField.delegate = self
        }
    }
    
    @IBOutlet private weak var rightEyeTextField: UITextField! {
        didSet {
            rightEyeTextField.delegate = self
        }
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        if textField == leftEyeTextField {
            checkInfo.osEyePressure = textField.text
        } else {
            checkInfo.odEyePressure = textField.text
        }
        
        delegate?.eyePressureCell(self, checkInfo: checkInfo)
    }
    
}
